﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Assignment_3
{
    public partial class FrHarold : Form
    {
        public FrHarold()
        {
            InitializeComponent();
            BuildTree();
        }

        private void BuildTree()
        {
            this.tvCourse.ExpandAll();

            Course[] Y200X = {
                                new Course("01/01/2007", "01/07/2007", "Begin Course", 20),
                                new Course("01/01/2008", "01/07/2008", "Advanced Course", 22),
                                new Course("01/01/2009", "01/07/2009", "Final Course", 23)
                             };

            for (int i = 0; i < this.tvCourse.Nodes[0].Nodes.Count; i++)
                this.tvCourse.Nodes[0].Nodes[i].Tag = Y200X[i];

            Subject A = new Subject("Syllabus of B1");
            Subject B = new Subject("Syllabus of B2");
            Subject C = new Subject("Syllabus of C1");
            Subject D = new Subject("Syllabus of D1");
            tvCourse.Nodes[0].Nodes[0].Nodes[0].Tag = A;
            tvCourse.Nodes[0].Nodes[0].Nodes[1].Tag = B;
            tvCourse.Nodes[0].Nodes[1].Nodes[0].Tag = C;
            tvCourse.Nodes[0].Nodes[2].Nodes[0].Tag = D;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void tvCourse_AfterSelect(object sender, TreeViewEventArgs e)
        {
            lvDetail.Items.Clear();
            lvDetail.Columns.Clear();
            // nut goc
            if (e.Node == this.tvCourse.Nodes[0])
            {
                lvDetail.View = View.List;
                lvDetail.Items.Add(new ListViewItem("This is the Business Course"));
            }
            else if (e.Node.Text.StartsWith("2"))
            {
                lvDetail.Columns.Add("StartDate", 140, HorizontalAlignment.Center);
                lvDetail.Columns.Add("EndStartDate", 70, HorizontalAlignment.Center);
                lvDetail.Columns.Add("Description", 70, HorizontalAlignment.Center);
                lvDetail.Columns.Add("Duration", 70, HorizontalAlignment.Center);
                lvDetail.View = View.Details;
                Course tmp = (Course)e.Node.Tag;
                ListViewItem item = new ListViewItem(tmp.StartDate);
                item.SubItems.Add(tmp.EndDate);
                item.SubItems.Add(tmp.Description);
                item.SubItems.Add(tmp.Duration.ToString());
                lvDetail.Items.Add(item);
            }
            else
            {
                Subject tmp = (Subject)e.Node.Tag;
                lvDetail.View = View.List;
                lvDetail.Items.Add(new ListViewItem(tmp.Syllabus));
            }
        }

        private void tvCourse_AfterSelect_1(object sender, TreeViewEventArgs e)
        {

        }


    }
}
